﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace SHOP
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        private const int pageSize = 5;

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Sản phẩm",
                "san-pham/{category}",
                new { controller = "product", category = UrlParameter.Optional , action = "Index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Chi tiết sản phẩm",
                "san-pham/chi-tiet/{product}",
                new { controller = "product", category = UrlParameter.Optional, product = UrlParameter.Optional, action = "Detail" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Giới thiệu",
                "gioi-thieu",
                new { controller = "info", action = "about" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Tuyển dụng",
                "tuyen-dung",
                new { controller = "info", action = "recruitment" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Hướng dẫn mua hàng",
                "huong-dan-mua-hang",
                new { controller = "info", action = "guide" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Giỏ hàng",
                "gio-hang",
                new { controller = "cart", action = "index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Thanh toán",
                "thanh-toan",
                new { controller = "checkout", action = "index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Đăng nhập",
                "dang-nhap",
                new { controller = "account", action = "index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Yêu thích",
                "yeu-thich",
                new { controller = "favorite", action = "index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Cập nhật",
                "tai-khoan",
                new { controller = "account", action = "update" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Thoát",
                "thoat",
                new { controller = "account", action = "logout" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Tim kiếm",
                "tim-kiem",
                new { controller = "search", action = "index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Liên hệ",
                "lien-he",
                new { controller = "contact", action = "index" },
                new[] { "SHOP.Controllers" }
            );

            routes.MapRoute(
                "Home", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
                new[] { "SHOP.Controllers" }
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // Use LocalDB for Entity Framework by default
            Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

       
    }
}